<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>安全知识每日一练</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 20px;
            background-color: #f4f4f4;
        }

        h1 {
            text-align: center;
            color: #333;
        }

        .question {
            background-color: #fff;
            border: 1px solid #ddd;
            border-radius: 5px;
            padding: 20px;
            margin-bottom: 20px;
        }

        .question p {
            margin: 0 0 10px;
        }

        .question label {
            display: block;
            margin-bottom: 5px;
        }

        button {
            display: block;
            width: 100%;
            padding: 10px;
            background-color: #007BFF;
            color: #fff;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }

        button:hover {
            background-color: #0056b3;
        }

        .result {
            margin-top: 20px;
            padding: 10px;
            background-color: #d4edda;
            border: 1px solid #c3e6cb;
            border-radius: 5px;
            color: #155724;
        }
    </style>
</head>

<body>
    <h1>安全知识每日一练</h1>
    <div id="quiz"></div>
    <button onclick="checkAnswers()">提交答案</button>
    <div id="result" class="result" style="display: none;"></div>

    <script>
        // 扩展后的题库
        const questions = {
            singleChoice: [
                // 电气安全题目
                {
                    question: "电气设备着火时，应首先采取的措施是？",
                    options: ["用水灭火", "切断电源", "用泡沫灭火器灭火"],
                    answer: "切断电源",
                    category: "电气安全"
                },
                {
                    question: "在电气设备上工作，保证安全的组织措施有？",
                    options: ["工作票制度", "工作许可制度", "以上都是"],
                    answer: "以上都是",
                    category: "电气安全"
                },
                {
                    question: "下列哪种工具不适合用于带电作业？",
                    options: ["绝缘手套", "普通钳子", "绝缘螺丝刀"],
                    answer: "普通钳子",
                    category: "电气安全"
                },
                {
                    question: "电气设备的金属外壳必须采取什么措施？",
                    options: ["接地保护", "接零保护", "以上都可以"],
                    answer: "以上都可以",
                    category: "电气安全"
                },
                {
                    question: "发现电气设备冒烟或有异味时，应立即？",
                    options: ["靠近检查", "切断电源", "继续使用观察"],
                    answer: "切断电源",
                    category: "电气安全"
                },
                {
                    question: "使用电气设备时，应先检查？",
                    options: ["设备外观", "设备接地情况", "以上都是"],
                    answer: "以上都是",
                    category: "电气安全"
                },
                {
                    question: "在潮湿场所使用电气设备，应选用？",
                    options: ["普通电气设备", "防潮型电气设备", "防爆型电气设备"],
                    answer: "防潮型电气设备",
                    category: "电气安全"
                },
                {
                    question: "电气设备的熔断器熔体熔断后，应？",
                    options: ["更换相同规格的熔体", "更换更大规格的熔体", "不做处理继续使用"],
                    answer: "更换相同规格的熔体",
                    category: "电气安全"
                },
                {
                    question: "下列哪种情况不会导致电气火灾？",
                    options: ["短路", "过载", "正确使用电气设备"],
                    answer: "正确使用电气设备",
                    category: "电气安全"
                },
                {
                    question: "检修电气设备时，应在开关处悬挂什么标识牌？",
                    options: ["止步，高压危险！", "有人工作，禁止合闸！", "在此工作！"],
                    answer: "有人工作，禁止合闸！",
                    category: "电气安全"
                },
                // 有限空间作业题目
                {
                    question: "有限空间作业前，必须进行的操作是？",
                    options: ["直接进入作业", "进行通风和气体检测", "不做任何准备"],
                    answer: "进行通风和气体检测",
                    category: "有限空间作业"
                },
                {
                    question: "有限空间作业中，发现有人中毒晕倒，应？",
                    options: ["立即进入救援", "佩戴好防护用具再进入救援", "等待专业人员"],
                    answer: "佩戴好防护用具再进入救援",
                    category: "有限空间作业"
                },
                {
                    question: "有限空间作业时，应设置什么人员？",
                    options: ["监护人", "作业人员", "两者都需要"],
                    answer: "两者都需要",
                    category: "有限空间作业"
                },
                {
                    question: "进入有限空间前，应进行什么通风？",
                    options: ["自然通风", "强制通风", "以上都可以"],
                    answer: "以上都可以",
                    category: "有限空间作业"
                },
                {
                    question: "有限空间内的氧气含量应保持在？",
                    options: ["18% - 21%", "15% - 18%", "21% - 24%"],
                    answer: "18% - 21%",
                    category: "有限空间作业"
                },
                {
                    question: "在有限空间作业时，应携带什么设备？",
                    options: ["对讲机", "气体检测仪", "以上都是"],
                    answer: "以上都是",
                    category: "有限空间作业"
                },
                {
                    question: "有限空间作业结束后，应进行什么检查？",
                    options: ["人员清点", "设备清点", "以上都是"],
                    answer: "以上都是",
                    category: "有限空间作业"
                },
                {
                    question: "有限空间内存在易燃易爆气体时，应使用什么工具？",
                    options: ["铁质工具", "铜质工具", "普通工具"],
                    answer: "铜质工具",
                    category: "有限空间作业"
                },
                {
                    question: "下列哪种情况不属于有限空间？",
                    options: ["地下室", "通风良好的车间", "污水井"],
                    answer: "通风良好的车间",
                    category: "有限空间作业"
                },
                {
                    question: "有限空间作业时，如遇紧急情况应？",
                    options: ["立即撤离", "继续作业", "等待救援"],
                    answer: "立即撤离",
                    category: "有限空间作业"
                },
                // 高空作业题目
                {
                    question: "高空作业时，必须佩戴的安全装备是？",
                    options: ["安全帽", "安全带", "两者都需要"],
                    answer: "两者都需要",
                    category: "高空作业"
                },
                {
                    question: "高空作业平台的最大承受重量应？",
                    options: ["超过实际使用重量", "等于实际使用重量", "不超过额定承载重量"],
                    answer: "不超过额定承载重量",
                    category: "高空作业"
                },
                {
                    question: "高空作业时，应设置什么设施？",
                    options: ["安全网", "防护栏杆", "以上都是"],
                    answer: "以上都是",
                    category: "高空作业"
                },
                {
                    question: "在恶劣天气条件下，是否可以进行高空作业？",
                    options: ["可以", "不可以", "视情况而定"],
                    answer: "不可以",
                    category: "高空作业"
                },
                {
                    question: "高空作业人员应具备什么条件？",
                    options: ["身体健康", "经过专业培训", "以上都是"],
                    answer: "以上都是",
                    category: "高空作业"
                },
                {
                    question: "高空作业时，工具应如何放置？",
                    options: ["随意放置", "放在工具袋内", "放在作业平台边缘"],
                    answer: "放在工具袋内",
                    category: "高空作业"
                },
                {
                    question: "高空作业时，禁止进行什么行为？",
                    options: ["抛掷工具", "上下传递工具", "佩戴安全带"],
                    answer: "抛掷工具",
                    category: "高空作业"
                },
                {
                    question: "高空作业结束后，应清理什么？",
                    options: ["工具", "材料", "以上都是"],
                    answer: "以上都是",
                    category: "高空作业"
                },
                {
                    question: "下列哪种情况不属于高空作业？",
                    options: ["在地面上操作设备", "在脚手架上作业", "在屋顶上维修"],
                    answer: "在地面上操作设备",
                    category: "高空作业"
                },
                {
                    question: "高空作业时，如遇身体不适，应？",
                    options: ["继续作业", "立即停止作业并撤离", "坚持完成任务"],
                    answer: "立即停止作业并撤离",
                    category: "高空作业"
                }
            ],
            multipleChoice: [
                {
                    question: "以下哪些属于电气安全防护措施？",
                    options: ["绝缘", "屏护", "间距", "接地"],
                    answer: ["绝缘", "屏护", "间距", "接地"],
                    category: "电气安全"
                },
                {
                    question: "有限空间作业前应做好哪些准备工作？",
                    options: ["制定作业方案", "进行风险评估", "配备防护设备", "设置警示标识"],
                    answer: ["制定作业方案", "进行风险评估", "配备防护设备", "设置警示标识"],
                    category: "有限空间作业"
                },
                {
                    question: "高空作业时，应遵循以下哪些原则？",
                    options: ["系好安全带", "严禁抛掷工具", "设置专人监护", "定期检查设备"],
                    answer: ["系好安全带", "严禁抛掷工具", "设置专人监护", "定期检查设备"],
                    category: "高空作业"
                }
            ],
            trueFalse: [
                {
                    question: "电气设备可以在潮湿环境中长时间使用而无需特殊防护。",
                    answer: false,
                    category: "电气安全"
                },
                {
                    question: "有限空间作业时，只要感觉没有危险就可以不佩戴防护用具。",
                    answer: false,
                    category: "有限空间作业"
                },
                {
                    question: "高空作业时，可以在没有防护措施的情况下攀爬脚手架。",
                    answer: false,
                    category: "高空作业"
                }
            ]
        };

        // 随机选择题目
        function getRandomQuestions() {
            const singleChoiceQuestions = getRandomSubset(questions.singleChoice, 5);
            const multipleChoiceQuestions = getRandomSubset(questions.multipleChoice, 3);
            const trueFalseQuestions = getRandomSubset(questions.trueFalse, 2);

            return [...singleChoiceQuestions, ...multipleChoiceQuestions, ...trueFalseQuestions];
        }

        // 从数组中随机选择指定数量的元素
        function getRandomSubset(arr, num) {
            const shuffled = [...arr].sort(() => Math.random() - 0.5);
            return shuffled.slice(0, num);
        }

        // 生成题目
        function generateQuiz() {
            const quizDiv = document.getElementById('quiz');
            const randomQuestions = getRandomQuestions();
            randomQuestions.forEach((question, index) => {
                const questionDiv = document.createElement('div');
                questionDiv.classList.add('question');
                questionDiv.innerHTML = `
                    <p>${index + 1}. ${question.question}</p>
                `;
                if (Array.isArray(question.options)) {
                    // 单选题或多选题
                    const inputType = Array.isArray(question.answer) ? 'checkbox' : 'radio';
                    question.options.forEach((option) => {
                        const label = document.createElement('label');
                        label.innerHTML = `
                            <input type="${inputType}" name="question${index}" value="${option}">
                            ${option}
                        `;
                        questionDiv.appendChild(label);
                    });
                } else {
                    // 判断题
                    ['正确', '错误'].forEach((option) => {
                        const label = document.createElement('label');
                        label.innerHTML = `
                            <input type="radio" name="question${index}" value="${option === '正确'}">
                            ${option}
                        `;
                        questionDiv.appendChild(label);
                    });
                }
                quizDiv.appendChild(questionDiv);
            });
        }

        // 检查答案
        function checkAnswers() {
            const quizDiv = document.getElementById('quiz');
            const resultDiv = document.getElementById('result');
            const randomQuestions = getRandomQuestions();
            let score = 0;
            let feedback = '';

            randomQuestions.forEach((question, index) => {
                const selectedOptions = document.querySelectorAll(`input[name="question${index}"]:checked`);
                let userAnswer;
                if (selectedOptions.length > 0) {
                    if (Array.isArray(question.answer)) {
                        // 多选题
                        userAnswer = Array.from(selectedOptions).map(option => option.value);
                        const isCorrect = userAnswer.length === question.answer.length &&
                            userAnswer.every(ans => question.answer.includes(ans));
                        if (isCorrect) {
                            score++;
                            feedback += `第 ${index + 1} 题回答正确！<br>`;
                        } else {
                            feedback += `第 ${index + 1} 题回答错误，正确答案是：${question.answer.join(', ')}<br>`;
                        }
                    } else {
                        // 单选题或判断题
                        userAnswer = selectedOptions[0].value;
                        const correctAnswer = typeof question.answer === 'boolean' ? String(question.answer) : question.answer;
                        if (userAnswer === correctAnswer) {
                            score++;
                            feedback += `第 ${index + 1} 题回答正确！<br>`;
                        } else {
                            const displayAnswer = typeof question.answer === 'boolean' ? (question.answer ? '正确' : '错误') : question.answer;
                            feedback += `第 ${index + 1} 题回答错误，正确答案是：${displayAnswer}<br>`;
                        }
                    }
                } else {
                    const displayAnswer = typeof question.answer === 'boolean' ? (question.answer ? '正确' : '错误') : (Array.isArray(question.answer) ? question.answer.join(', ') : question.answer);
                    feedback += `第 ${index + 1} 题未作答，正确答案是：${displayAnswer}<br>`;
                }
            });

            feedback += `你的得分是：${score} / ${randomQuestions.length}`;
            resultDiv.innerHTML = feedback;
            resultDiv.style.display = 'block';

            // 存储打卡数据
            const today = new Date().toLocaleDateString();
            const 打卡Data = JSON.parse(localStorage.getItem('打卡Data')) || {};
            打卡Data[today] = score;
            localStorage.setItem('打卡Data', JSON.stringify(打卡Data));
        }

        // 页面加载时生成题目
        window.onload = generateQuiz;
    </script>
</body>

</html>